String.Format = function() {
	if (arguments.length == 0)
		return null;
	var str = arguments[0];
	for (var i = 1; i < arguments.length; i++) {
		var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
		var value = arguments[i] ? arguments[i].toString() : '';
		if (str) {
			str = str.replace(re, value);
		}
	}
	return str;
};

String.isEmptyOrNUll = function() {
	if (arguments.length == 0)
		return true;
	var v = arguments[0];
	if (v == undefined) return true;
	if ((v + "").length <= 0) return true
	return false;
};
Array.isAllNotEmpty = function(arr) {
	if (arguments.length == 0) {
		return false
	}
	for (var i = 0; i < arr.length; i++) {
		if (String.isEmptyOrNUll(arr[i])) {
			return false;
		}
	}
	return true;
}
String.prototype.replaceAll = function(reallyDo, replaceWith) {
	if (!this || this.length <= 0) {
		return '';
	}
	return this.replace(new RegExp(reallyDo, "gm"), replaceWith);
}
String.containValue = function(str1, str2) {
	if (str1 == undefined) return false;
	return str1.indexOf(str2) >= 0;
}
Array.prototype.indexOf = function(obj, key) {
	for (var i = 0, len = this.length; i < len; i++) {
		if (key) {
			if (this[i][key] == obj)
				return i;
		}
		if (this[i] == obj) {
			return i;
		}
	}
	return -1;
};
Array.prototype.findAt = function(obj, key) {
	for (var i = 0, len = this.length; i < len; i++) {
		if (key) {
			if (this[i][key] == obj)
				return i;
		}
		if (this[i] == obj) {
			return i;
		}
	}
	return -1;
};
Array.prototype.removeAt = function(index) {
	this.splice(index, 1);
};
Array.prototype.remove = function(obj, key) {
	var index = this.indexOf(obj, key);
	if (index >= 0) {
		this.removeAt(index);
	}
};

Array.prototype.find = function(func) {
	for (var i = 0; i < this.length; i++) {
		if (func(this[i], i) == true) {
			return this[i];
		}
	}

}
Array.prototype.findAll = function(func) {
	var lst = [];
	for (var i = 0; i < this.length; i++) {
		if (func(this[i], i) == true) {
			lst.push(this[i]);
		}
	}
	return lst;
};
Array.prototype.insert = function(index, item) {
	this.splice(index, 0, item);
};
Array.prototype.getIndexSafe = function(index, Key) {
	if (index > this.length - 1) {
		return undefined;
	} else if (!Key) {
		return this[index];
	} else {
		return this[index][Key];
	}
}

Date.prototype.Format = function(formatStr) {
	var str = formatStr;
	var month = this.getMonth() + 1;

	var Week = ['日', '一', '二', '三', '四', '五', '六'];

	str = str.replace(/yyyy|YYYY/, this.getFullYear());
	str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() %
		100));

	str = str.replace(/MM/, month > 9 ? month.toString() : '0' + month);
	str = str.replace(/M/g, month);

	str = str.replace(/w|W/g, Week[this.getDay()]);

	str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
	str = str.replace(/d|D/g, this.getDate());

	str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
	str = str.replace(/h|H/g, this.getHours());
	str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
	str = str.replace(/m/g, this.getMinutes());

	str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
	str = str.replace(/s|S/g, this.getSeconds());

	return str;
}

Date.prototype.DateAdd = function(strInterval, Number) {
	var dtTmp = this;
	switch (strInterval) {
		case 's':
			return new Date(Date.parse(dtTmp) + (1000 * Number));
		case 'n':
			return new Date(Date.parse(dtTmp) + (60000 * Number));
		case 'h':
			return new Date(Date.parse(dtTmp) + (3600000 * Number));
		case 'd':
			return new Date(Date.parse(dtTmp) + (86400000 * Number));
		case 'w':
			return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));
		case 'q':
			return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number * 3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(),
				dtTmp.getSeconds());
		case 'm':
			return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(),
				dtTmp.getSeconds());
		case 'y':
			return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(),
				dtTmp.getSeconds());
	}
}
